package com.demo.cms.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.TermVector;

import com.demo.core.model.support.SimpleBaseModel;
import com.demo.search.annotation.Searchable;
import com.demo.search.annotation.SearchableProperty;

/**
 * 文章模型
 * 在CMS中,文章模型是最小的数据单位
 * 文章模型中
 * 
 * @author ryuu.kk
 *
 */
@Searchable
public class Article extends SimpleBaseModel implements java.io.Serializable {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = -3004238109309016562L;
	
	/**
	 * 文章类型：文字类型
	 */
	public static final String TYPE_NORMAL = "normal";
	
	/**
	 * 文章类型：全图片文章
	 */
	public static final String TYPE_IMAGE = "image";
	
	/**
	 * 文章类型：多媒体文章
	 */
	public static final String TYPE_MEDIA = "media";
	
	/**
	 * 文章类型：复合类型文章
	 */
	public static final String TYPE_MULTI = "multi";
	
	/**
	 * 站点ID
	 */
	@SearchableProperty
	private Long siteId;
	
	/**
	 * 栏目外键ID
	 */
	@SearchableProperty
	private Long categoryId;
	
	@SearchableProperty(name="categoryTitle")
	private String categoryTitle;
	
	/**
	 * 栏目路径(生成链接用)
	 */
	@SearchableProperty
	private String categoryPath;
	
	/**
	 * 频道路径(生成链接用)
	 */
	@SearchableProperty
	private String channelPath;
	
	/**
	 * 模板ID
	 */
	@SearchableProperty
	private Long templateId;
	
	/**
	 * 栏目标题
	 */
	@SearchableProperty(index = Index.ANALYZED, termVector = TermVector.WITH_POSITIONS_OFFSETS, allowHighlighter = true)
	private String title;
	
	/**
	 * 栏目关键字
	 */
	@SearchableProperty
	private String keyWords;
	
	/**
	 * 栏目短标题
	 */
	@SearchableProperty
	private String shortTitle;
	
	/**
	 * 标题缩略图
	 */
	private String titleImg;
	
	/**
	 * 文章的其他类型文件的文件夹
	 */
	private Long folderId;
	
	/**
	 * 描述
	 */
	@SearchableProperty(index = Index.ANALYZED)
	private String description;
	
	/**
	 * 标签
	 */
	@SearchableProperty
	private String tags;
	
	/**
	 * 文章作者
	 */
	@SearchableProperty
	private String author;
	
	/**
	 * 文章来源
	 */
	@SearchableProperty
	private String origin;
	
	/**
	 * 文章置顶级别
	 */
	@SearchableProperty
	private String topLevel;
	
	/**
	 * 文章审核级别
	 */
	private String checkLevel;
	
	/**
	 * 文章排序
	 */
	private String sort;
	
	/**
	 * 文章发布时间（可人为设置）
	 */
	@SearchableProperty
	private Date publishDate;
	
	/**
	 * 文章外部链接
	 */
	private String outerUrl;
	
	/**
	 * 文章总页数
	 */
	private int pageCount;
	
	/**
	 * 文章是否允许评论
	 */
	private Boolean isComment = false;
	
	/**
	 * 评论条数
	 */
	private int commentCount;
	
	/**
	 * 是否对文章进行分析
	 */
	private Boolean isAnalyse = false;
	
	/**
	 * 是否对文章进行索引
	 */
	private Boolean isIndex = true;
	
	/**
	 * 文章是否草稿状态
	 */
	private Boolean isDraft = false;
	
	/**
	 * 文章是否推荐
	 */
	private Boolean isRecommend = false;
	
	/**
	 * 文章是否需要审核
	 */
	private Boolean isCheck = false;
	
	/**
	 * 文章审核是否通过
	 */
	private Boolean isReject = false;

	/**
	 * 文章是否需要许可访问
	 */
	private Boolean isPermission = false;
	
	/**
	 * 文章类型
	 */
	@SearchableProperty
	private String type;
	
	/**
	 * 文章是否可用
	 */
	private Boolean enabled = true;
	
	/**
	 * 文章状态
	 */
	private String status;
	
	/**
	 * 文章国际化CODE
	 */
	private String i18n;
	
	/**
	 * 文章包含所有内容
	 */
	@SearchableProperty(name = "content", 
			index = Index.ANALYZED, 
			termVector = TermVector.WITH_POSITIONS_OFFSETS, 
			allowHighlighter = true, 
			propertyConverter = "HTML")
	private List<ArticleContent> contentList;

	/**
	 * 文章的扩展属性
	 */
	private List<ArticleExtend> extendList; 
	
	public Long getSiteId() {
		return siteId;
	}

	public void setSiteId(Long siteId) {
		this.siteId = siteId;
	}
	
	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}

	public String getChannelPath() {
		return channelPath;
	}

	public void setChannelPath(String channelPath) {
		this.channelPath = channelPath;
	}

	public String getCategoryPath() {
		return categoryPath;
	}

	public void setCategoryPath(String categoryPath) {
		this.categoryPath = categoryPath;
	}

	public String getCategoryTitle() {
		return categoryTitle;
	}

	public void setCategoryTitle(String categoryTitle) {
		this.categoryTitle = categoryTitle;
	}

	public Long getTemplateId() {
		return templateId;
	}

	public void setTemplateId(Long templateId) {
		this.templateId = templateId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getKeyWords() {
		return keyWords;
	}

	public void setKeyWords(String keyWords) {
		this.keyWords = keyWords;
	}

	public String getShortTitle() {
		return shortTitle;
	}

	public void setShortTitle(String shortTitle) {
		this.shortTitle = shortTitle;
	}

	public String getTitleImg() {
		return titleImg;
	}

	public void setTitleImg(String titleImg) {
		this.titleImg = titleImg;
	}

	public Long getFolderId() {
		return folderId;
	}

	public void setFolderId(Long folderId) {
		this.folderId = folderId;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getOrigin() {
		return origin;
	}

	public void setOrigin(String origin) {
		this.origin = origin;
	}

	public String getTopLevel() {
		return topLevel;
	}

	public void setTopLevel(String topLevel) {
		this.topLevel = topLevel;
	}

	public String getCheckLevel() {
		return checkLevel;
	}

	public void setCheckLevel(String checkLevel) {
		this.checkLevel = checkLevel;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public Date getPublishDate() {
		return publishDate;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	public String getOuterUrl() {
		return outerUrl;
	}

	public void setOuterUrl(String outerLine) {
		this.outerUrl = outerLine;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public Boolean isComment() {
		return isComment;
	}

	public void setComment(Boolean isComment) {
		this.isComment = isComment;
	}

	public int getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(int commentCount) {
		this.commentCount = commentCount;
	}

	public Boolean isAnalyse() {
		return isAnalyse;
	}

	public void setAnalyse(Boolean isAnalyse) {
		this.isAnalyse = isAnalyse;
	}

	public Boolean isIndex() {
		return isIndex;
	}

	public void setIndex(Boolean isIndex) {
		this.isIndex = isIndex;
	}

	public Boolean isDraft() {
		return isDraft;
	}

	public void setDraft(Boolean isDraft) {
		this.isDraft = isDraft;
	}

	public Boolean isRecommend() {
		return isRecommend;
	}

	public void setRecommend(Boolean isRecommend) {
		this.isRecommend = isRecommend;
	}

	public Boolean isCheck() {
		return isCheck;
	}

	public void setCheck(Boolean isCheck) {
		this.isCheck = isCheck;
	}

	public Boolean isReject() {
		return isReject;
	}

	public void setReject(Boolean isReject) {
		this.isReject = isReject;
	}

	public Boolean isPermission() {
		return isPermission;
	}

	public void setPermission(Boolean isPermission) {
		this.isPermission = isPermission;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getI18n() {
		return i18n;
	}

	public void setI18n(String i18n) {
		this.i18n = i18n;
	}

	public List<ArticleContent> getContentList() {
		return contentList;
	}

	public void setContentList(List<ArticleContent> contentAll) {
		this.contentList = contentAll;
	}

	public List<ArticleExtend> getExtendList() {
		return extendList;
	}

	public void setExtendList(List<ArticleExtend> articleExtendList) {
		this.extendList = articleExtendList;
	}

	/**
	 * 加入文章内容
	 * 将新增内容加入到文章的首页
	 * @param content 文章内容
	 */
	public void addContent(ArticleContent content) {
		if (this.contentList == null) {
			contentList = new ArrayList<ArticleContent>();
		}
		contentList.add(content);
	}
	
	/**
	 * 加入文章扩展属性
	 * 将新增扩展属性模型加入到文章
	 * @param extend 文章扩展属性模型
	 */
	public void addExtend(ArticleExtend extend) {
		if (this.extendList == null) {
			extendList = new ArrayList<ArticleExtend>();
		}
		extendList.add(extend);
	}
}
